/*
 * Copyright (c) 2020 Fraunhofer FOKUS and others. All rights reserved.
 *
 * See the NOTICE file(s) distributed with this work for additional
 * information regarding copyright ownership.
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License 2.0 which is available at
 * http://www.eclipse.org/legal/epl-2.0
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contact: mosaic@fokus.fraunhofer.de
 */
package org.eclipse.mosaic.lib.geo;

import org.eclipse.mosaic.lib.junit.GeoProjectionRule;
import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TestRule;
import org.junit.runner.RunWith;
import org.mockito.junit.MockitoJUnitRunner;

@RunWith(MockitoJUnitRunner.class)
public class GeoSectorTest {

    private static GeoPoint BERLIN = GeoPoint.latLon(52.5, 13.4);

    @Rule
    public TestRule geoProjectionRule = new GeoProjectionRule(BERLIN);

    @Test
    public void getBounds() {
        // set up
        GeoPoint center = GeoPoint.latLon(52.5, 13.7);

        // 0-90 degree
        GeoSector sector1 = new GeoSector(center, 100, 0, 30);
        Bounds<GeoPoint> bounds1 = sector1.getBounds();
        Assert.assertEquals(5000, bounds1.getArea(), 0.1d);

        // 90-180 degree
        GeoSector sector2 = new GeoSector(center, 100, 30, 150);
        Bounds<GeoPoint> bounds2 = sector2.getBounds();
        Assert.assertEquals(10000, bounds2.getArea() / Math.sqrt(3), 0.1d);

        // 180-360 degree
        GeoSector sector3 = new GeoSector(center, 100, 45, 315);
        Bounds<GeoPoint> bounds3 = sector3.getBounds();
        Assert.assertEquals(20000, bounds3.getArea() / (1 + Math.sqrt(2) / 2), 0.1d);
    }

    @Test
    public void testDistance() {
        GeoPoint point1 = GeoPoint.latLon(52.5, 13.7);
        GeoPoint point2 = GeoPoint.latLon(52.51, 13.71);

        System.out.println(point1.distanceTo(point2));
        System.out.println(GeoUtils.azimuth(point1, point2));
    }

    @Test
    public void testContains() {
        // set up
        GeoPoint center = GeoPoint.latLon(52.5, 13.7);

        GeoSector sector = new GeoSector(center, 1350, 0, 32);

        GeoPoint point = GeoPoint.latLon(52.51, 13.71);
        Assert.assertTrue(sector.contains(point));
    }


    @Test
    public void testEquals() {
        GeoPoint center1 = GeoPoint.latLon(52.5, 13.7);
        GeoSector sector1 = new GeoSector(center1, 1350, 0, 32);

        GeoPoint center2 = GeoPoint.latLon(52.5, 13.7);
        GeoSector sector2 = new GeoSector(center2, 1350, 0, 32);

        Assert.assertEquals(sector1, sector2);
    }
}
